package 面试v1.字节;

import leetcodev1.链表.Solution;

import java.util.Arrays;

public class LeetCode204 {

    public int countPrimes(int n) {
        int[] isPrime = new int[n];
        Arrays.fill(isPrime, 1);//默认是质数
        int ans = 0;
        for (int i = 2; i < n; ++i) {
            if (isPrime[i] == 1) {
                ans += 1;
                for (int j = 0; i * j < n; j++) {
                    isPrime[i * j] = 0;
                }
            }
        }
        return ans;
    }
}
